package interview.net.socket;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author: Jun
 * @Date: 2018/9/8 20:05
 */
public class Server {
    private ServerSocket serverSocket;
    private Socket socket;
    private BufferedReader br;
    private PrintWriter pw;

    public Server() {
        try {
            serverSocket = new ServerSocket(8888);
            while (true) {
                socket = serverSocket.accept();
                String ip = socket.getInetAddress().getHostAddress();
                int localPort = socket.getLocalPort();
                System.out.println("Weclome" + ip + ":" + localPort);
                br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                String line = br.readLine();
                System.out.println(line);
//                pw = new PrintWriter(socket.getOutputStream(), true);
//                pw.println("sfasf");
//                pw.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
         new Server();
    }
}
